package service

import (
	__ "base_srv/basic/baseproto"
	"base_srv/handler/dao"
	"context"
)

// ApplicationList 应用列表
func (s *Server) ApplicationList(_ context.Context, in *__.ApplicationListReq) (*__.ApplicationListResp, error) {
	list, err := dao.ApplicationList()
	if err != nil {
		return nil, err
	}
	return &__.ApplicationListResp{ApplicationList: list}, nil
}

// ApplicationAdd 应用添加
func (s *Server) ApplicationAdd(_ context.Context, in *__.ApplicationAddReq) (*__.ApplicationAddResp, error) {
	id, err := dao.ApplicationAdd(in)
	if err != nil {
		return nil, err
	}
	return &__.ApplicationAddResp{Id: int64(id)}, nil
}

// ApplicationUpdate 应用更新
func (s *Server) ApplicationUpdate(_ context.Context, in *__.ApplicationUpdateReq) (*__.ApplicationUpdateResp, error) {
	err := dao.ApplicationUpdate(in)
	if err != nil {
		return nil, err
	}
	return &__.ApplicationUpdateResp{Id: in.Id}, nil
}

// ApplicationUpdateWithoutFile 应用修改（无文件）
func (s *Server) ApplicationUpdateWithoutFile(_ context.Context, in *__.ApplicationUpdateWithoutFileReq) (*__.ApplicationUpdateWithoutFileResp, error) {
	err := dao.ApplicationUpdateWithoutFile(in)
	if err != nil {
		return nil, err
	}
	return &__.ApplicationUpdateWithoutFileResp{Id: in.Id}, nil
}

// ApplicationDelete 应用删除
func (s *Server) ApplicationDelete(_ context.Context, in *__.ApplicationDeleteReq) (*__.ApplicationDeleteResp, error) {
	err := dao.ApplicationDelete(in)
	if err != nil {
		return nil, err
	}
	return &__.ApplicationDeleteResp{Id: in.Id}, nil
}
